package io.lvdaxian.mybatis.session.defaults;

import io.lvdaxian.mybatis.binding.MapperRegistry;
import io.lvdaxian.mybatis.session.SqlSession;

/**
 * DefaultSqlSession 是对象接口【SqlSession】的实现
 *
 * @author lihh
 */
public class DefaultSqlSession implements SqlSession {
  
  // 这是 mapper register 注册器
  private final MapperRegistry mapperRegistry;
  
  public DefaultSqlSession(MapperRegistry mapperRegistry) {
    this.mapperRegistry = mapperRegistry;
  }
  
  @Override
  public <T> T selectOne(String statement) {
    return (T) ("你被代理了！" + "方法：" + statement);
  }
  
  @Override
  public <T> T selectOne(String statement, Object parameter) {
    return (T) ("你被代理了！" + "方法：" + statement + " 入参：" + parameter);
  }
  
  @Override
  public <T> T getMapper(Class<T> clazz) {
    return mapperRegistry.getMapper(clazz, this);
  }
}
